package so.ifl.commons.tools.xml;
import java.util.Map;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import so.ifl.commons.tools.StringHelper;

/**
 *create by aaron.lu
 *create at 2012-3-18 上午11:29:37
 *<mailto: atyuan.lu@gmail.com>
 **/
public class XMLContentHandler extends DefaultHandler {
	
	private Map<String, Object> rs;
	private String tagName; 
	
	public XMLContentHandler(Map<String, Object> rs) {   
        this.rs = rs;   
    }   

    @Override  
    public void characters(char[] ch, int start, int length)throws SAXException {   
        String tmp = new String(ch, start, length);    
        if (StringHelper.isNotEmpty(tagName) && StringHelper.isNotEmpty(tmp) && !tmp.equals("\n")) {
        	rs.put(tagName, tmp);
		}
        
    }   
  
    @Override  
    public void endDocument() throws SAXException {   
        super.endDocument();   
    }   
  
    @Override  
    public void endElement(String uri, String localName, String qName)   
            throws SAXException {   
        tagName = "";   
    }   
  
    @Override  
    public void startDocument() throws SAXException {   
        super.startDocument();   
    }   
  
    @Override  
    public void startElement(String uri, String localName, String qName,  Attributes attributes) throws SAXException {   
        this.tagName = localName;   
        if ("".equals(localName)) {   
            this.tagName = qName;   
        }   
    }

	public Map<String, Object> getRs() {
		return rs;
	}

	public void setRs(Map<String, Object> rs) {
		this.rs = rs;
	}
    
    
}
